package com.ruoyi.web.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.data.ChartMultiSeriesRenderData;
import com.deepoove.poi.data.ChartSingleSeriesRenderData;
import com.deepoove.poi.data.Charts;
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.service.ISysConfigService;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class WordController {

    public static void main(String[] args) throws Exception{
        String path = System.getProperty("user.dir") + "/ruoyi-admin/src/main/resources/te/1.docx";
        File sourceFile = new File(path);

        Map<String, Object> data = new HashMap();
        data.put("name", "jiefei");
        data.put("age", "18");
        data.put("address", "福建福清");

        LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();

        Student student1 = new Student();
        student1.setAge("12");
        student1.setIndex("1");
        student1.setName("张三");
        student1.setSex("男");
        Student student2 = new Student();
        student2.setAge("13");
        student2.setIndex("2");
        student2.setName("李四");
        student2.setSex("男1");
        List<Student> studentList = Arrays.asList(student1,student2);

        data.put("lists",studentList);
        Configure config = Configure.builder()
            .bind("lists", policy).build();

        ChartMultiSeriesRenderData pie = Charts
            .ofMultiSeries(null, new String[]{"家居","厨房用品","文具"})
            .addSeries("商品数量", new Integer[]{66,13,21})
            .create();



        data.put("line", pie);
//创建输出流
        OutputStream os = new FileOutputStream("d:/template1_out.docx");
//最终编译渲染并输出
        XWPFTemplate.compile(sourceFile,config).render(data).writeAndClose(os);

    }

}
@Data
 class Student {
    private String age;
    private String index;
    private  String name;
    private String sex;
    private String sexs;
}

